package web.suzy.oj.service.file.impl;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.exception.StatusForbiddenException;
import web.suzy.oj.common.exception.StatusSystemErrorException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.common.result.ResultStatus;
import web.suzy.oj.manager.file.MarkDownFileManager;
import web.suzy.oj.service.file.MarkDownFileService;

import javax.annotation.Resource;
import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: MarkDownFileServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/12/8 11:18
 */
@Service
public class MarkDownFileServiceImpl implements MarkDownFileService {
    @Resource
    private MarkDownFileManager markDownFileManager;

    /**
     * 方法名: uploadMd
     * 描述: 上传markdown文件
     *
     * @param file
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/12/8 11:19
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Map<Object, Object>> uploadMd(MultipartFile file) {
        try {
            return ResultBean.successResponse(markDownFileManager.uploadMd(file));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        } catch (StatusForbiddenException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.FORBIDDEN);
        }
    }

    /**
     * 方法名: uploadMDImg
     * 描述: markdown上传照片
     *
     * @param image
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/12/8 15:06
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Map<Object, Object>> uploadMDImg(MultipartFile image) {
        try {
            return ResultBean.successResponse(markDownFileManager.uploadMDImg(image));
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusSystemErrorException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.SYSTEM_ERROR);
        } catch (StatusForbiddenException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.FORBIDDEN);
        }
    }

    /**
     * 方法名: deleteMDImg
     * 描述: markdown删除图片
     *
     * @param fileId
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/12/8 15:22
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> deleteMDImg(Long fileId) {
        try {
            markDownFileManager.deleteMDImg(fileId);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        } catch (StatusForbiddenException e) {
            return ResultBean.errorResponse(e.getMessage(), ResultStatus.FORBIDDEN);
        }
    }
}
